package com.nondo.rdp.core.domain.attach;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.nondo.rdp.core.common.CommUtil;
import com.nondo.rdp.core.domain.base.BaseEntity;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 附件表
 */
@Entity
@Table(name = "common_attach")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Attach extends BaseEntity {
	private static final long serialVersionUID = -4662380189856864165L;
	private Long id;    //自增ID
    private int type;   //类型，0=图片，1=音频，2=视频
    private String path;    //路径
    private String remark;      //备注
    private String videoId; //阿里云视频ID
    private List<AttachConfig> attachConfigs; //图片配置

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getPath() {
    	if (type == 0) {
			return CommUtil.getFileUrl(path);
		}
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getVideoId() {
		return videoId;
	}

	public void setVideoId(String videoId) {
		this.videoId = videoId;
	}

	@OneToMany(mappedBy = "id")
    @LazyCollection(LazyCollectionOption.EXTRA)
    @NotFound(action = NotFoundAction.IGNORE)
    public List<AttachConfig> getAttachConfigs() {
        return attachConfigs;
    }

    public void setAttachConfigs(List<AttachConfig> attachConfigs) {
        this.attachConfigs = attachConfigs;
    }
}
